#include <string>
#include <fstream>

struct node
{
    bool terminal;
    node * * next;
    node():
    terminal(false), next(0)
    {
             
    }
};

class aut
{
    unsigned n, alph_size_;
    char f_, l_;
    node * nodes_;
    unsigned char_number_(char);
public:
    aut(char, char);
    friend std::ifstream& operator >> (std::ifstream&, aut&);
    std::string check(std::string&);
};

unsigned aut::char_number_(char c)
{
    return c - f_;
}

aut::aut(char f, char l):
f_(f), l_(l), alph_size_(l - f + 1)
{
    
}

std::ifstream& operator >> (std::ifstream& in, aut& a)
{
    unsigned n, m, k, b, d;
    char c;
    in >> n >> m >> k;
    a.nodes_ = new node[n + 1];
    for (unsigned i = 1; i <= n; ++i)
    {
        a.nodes_[i].next = new node * [a.alph_size_];
        for (unsigned j = 0; j < a.alph_size_; ++j)
        {
            a.nodes_[i].next[j] = 0;
        }
    }
    for (unsigned i = 0; i < k; ++i)
    {
        in >> d;
        a.nodes_[d].terminal = true;
    }
    for (unsigned i = 0; i < m; ++i)
    {
        in >> b >> d >> c;
        a.nodes_[b].next[a.char_number_(c)] = a.nodes_ + d;
    }
    return in;
}

std::string aut::check(std::string& s)
{
    node * cur = nodes_ + 1;
    for (unsigned i = 0, l = s.length(); i < l && cur; ++i)
    {
        cur = cur->next[char_number_(s[i])];
    }
    if (!cur || !cur->terminal)
        return std::string("Rejects");
    else
        return std::string("Accepts");
}

int main()
{
    std::string s;
    std::ifstream in("problem1.in");
    std::ofstream out("problem1.out");
    aut a('a', 'z');
    in >> s;
    in >> a;
    out << a.check(s);
    return 0;
}